#ifndef __I2C1_H
#define __I2C1_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "delay.h"
/* Private define ------------------------------------------------------------*/
#define I2C1_SCL_GPIO_PORT GPIOD
#define I2C1_SCL_GPIO_RCC  RCC_AHB1Periph_GPIOD
#define I2C1_SCL_PIN       GPIO_Pin_2

#define I2C1_SDA_GPIO_PORT GPIOD
#define I2C1_SDA_GPIO_RCC  RCC_AHB1Periph_GPIOD
#define I2C1_SDA_PIN       GPIO_Pin_3

#define SCL1_H GPIO_SetBits(I2C1_SCL_GPIO_PORT, I2C1_SCL_PIN)
#define SCL1_L GPIO_ResetBits(I2C1_SCL_GPIO_PORT, I2C1_SCL_PIN)

#define SDA1_H GPIO_SetBits(I2C1_SDA_GPIO_PORT, I2C1_SDA_PIN)
#define SDA1_L GPIO_ResetBits(I2C1_SDA_GPIO_PORT, I2C1_SDA_PIN)

#define SCL1_read GPIO_ReadInputDataBit(I2C1_SCL_GPIO_PORT, I2C1_SCL_PIN)
#define SDA1_read GPIO_ReadInputDataBit(I2C1_SDA_GPIO_PORT, I2C1_SDA_PIN)

/* Private function prototypes -----------------------------------------------*/
void I2C1_Init(void);
FunctionalState I2C1_WriteByte(uint8_t SendByte, uint16_t WriteAddress, uint8_t DeviceAddress);
FunctionalState I2C1_ReadByte(uint8_t *pBuffer, uint16_t length, uint16_t ReadAddress, uint8_t DeviceAddress);
uint8_t IIC1_read_one_byte(uint16_t ReadAddr);
void IIC1_write_one_byte(uint16_t WriteAddr, uint8_t DataToWrite);
void IIC1_write_one_byte_CRC(uint16_t WriteAddr, uint16_t DataToWrite);
uint8_t IIC1_read_one_byte(uint16_t ReadAddr);
uint8_t CRC8(uint8_t *ptr, uint8_t len, uint8_t key);
#endif
